package org.project.single.controller.back;

import com.github.pagehelper.Page;
import org.project.single.pojo.ro.EnableRo;
import org.project.single.pojo.ro.menu.AuthMenuRo;
import org.project.single.pojo.ro.role.EditRoleBackRo;
import org.project.single.pojo.ro.role.RoleListBackRo;
import org.project.single.pojo.vo.role.RoleDetailBackVo;
import org.project.single.pojo.vo.role.RoleListBackVo;
import org.project.single.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.stone.project.baseCommon.pojo.vo.R;

import javax.validation.Valid;

/**
 * 角色后台接口
 */
@RestController
@RequestMapping("/back/role")
public class SysRoleBackController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 获取角色列表
     * @return
     */
    @GetMapping("getRoleList")
    public R<Page<RoleListBackVo>> getRoleList(RoleListBackRo roleListBackRo){
        return R.ok(sysRoleService.getRoleListBack(roleListBackRo));
    }

    /**
     * 角色详情
     * @return
     */
    @GetMapping("detail/{id}")
    public R<RoleDetailBackVo> getRoleDatail(@PathVariable String id){
        return R.ok(sysRoleService.getRoleDatailBack(id));
    }

    /**
     * 添加角色
     * @param editRoleBackRo
     * @return
     */
    @PostMapping("addRole")
    public R addRole(@RequestBody @Validated EditRoleBackRo editRoleBackRo){
        sysRoleService.editRoleBack(editRoleBackRo);
        return R.ok();
    }

    /**
     * 更新角色
     * @param editRoleBackRo
     * @return
     */
    @PutMapping("updateRole")
    public R updateRole(@RequestBody @Validated EditRoleBackRo editRoleBackRo){
        sysRoleService.editRoleBack(editRoleBackRo);
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deleteRole(@PathVariable String id){
        sysRoleService.deleteRole(id);
        return R.ok();
    }

    /**
     * 角色启用
     * @param enableRo
     * @return
     */
    @PostMapping("enableRole")
    public R enableRole(@RequestBody @Valid EnableRo enableRo){
        sysRoleService.enableRole(enableRo);
        return R.ok();
    }

    /**
     * 角色授权
     * @return
     */
    @PostMapping("authMenu")
    public R authMenu(@RequestBody @Valid AuthMenuRo authMenuRo){
        sysRoleService.authMenu(authMenuRo);
        return R.ok();
    }
}
